package LeetCode刷题;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2021-10-14 15:07
 * @description: Functions of this class is
 **/
public class 电话号码的字母组合 {
    public static void main(String[] args) {

    }
    public static List<String> letterCombinations(String digits) {
        int len=digits.length();
        List<String> ans=new ArrayList();
        if(len==0){
            return ans;
        }
        switch(len){
            case 1:{
                for(char c:getLetters(digits.charAt(0)).toCharArray()){
                    ans.add(String.valueOf(c));
                }
                break;
            }
            case 2:{
                char c1[]=getLetters(digits.charAt(0)).toCharArray();
                char c2[]=getLetters(digits.charAt(1)).toCharArray();
                for(int i=0;i<c1.length;i++){
                    for(int j=0;j<c2.length;j++){
                        String sub=String.valueOf(c1[i]);
                        sub+=c2[j];
                        if(!ans.contains(sub)){
                            ans.add(sub);
                        }
                    }
                }
                break;
            }
            case 3:{
                char c1[]=getLetters(digits.charAt(0)).toCharArray();
                char c2[]=getLetters(digits.charAt(1)).toCharArray();
                char c3[]=getLetters(digits.charAt(2)).toCharArray();
                for(int i=0;i<c1.length;i++){
                    for(int j=0;j<c2.length;j++){
                        for(int k=0;k<c3.length;k++){
                            String sub=String.valueOf(c1[i]);
                            sub+=c2[j];
                            sub+=c3[k];
                            if(!ans.contains(sub)){
                                ans.add(sub);
                            }
                        }
                    }
                }

                break;
            }
            default:{
                char c1[]=getLetters(digits.charAt(0)).toCharArray();
                char c2[]=getLetters(digits.charAt(1)).toCharArray();
                char c3[]=getLetters(digits.charAt(2)).toCharArray();
                char c4[]=getLetters(digits.charAt(3)).toCharArray();
                for(int i=0;i<c1.length;i++){
                    for(int j=0;j<c2.length;j++){
                        for(int k=0;k<c3.length;k++){
                            for(int x=0;x<c4.length;x++){
                                String sub=String.valueOf(c1[i]);
                                sub+=c2[j];
                                sub+=c3[k];
                                sub+=c4[x];
                                if(!ans.contains(sub)){
                                    ans.add(sub);
                                }
                            }
                        }
                    }
                }
            }
        }
        return ans;
    }
    private static String getLetters(char num){
        switch(num){
            case '2':return "abc";
            case '3':return "def";
            case '4':return "ghi";
            case '5':return "jkl";
            case '6':return "mno";
            case '7':return "pqrs";
            case '8':return "tuv";
            case '9':return "wxyz";
        }
        return "";
    }
}